(function () {
  var MAIN = "runjslint.js";
  var SOURCE = "fulljslint.js";
  var BUILD = "build";
  var JSDB = "C:\\Users\\Public\\Program\\jsdb\\jsdb.exe";
  var ZIP = "zip.exe";
  var OUT = "runjslint";
  
  function Cmd(program) {
    writeln(program);
    this.s = new Stream("exec://" + program, "d");
    writeln(this.s.readln());
  }
  
  Cmd.prototype = {
    write: function (s) {
      this.s.writeln(s);
      system.sleep(10);
      this.read();
    },
    
    read: function () {
      while (this.s.canRead) {
        write(this.s.get());
      }
    },
    
    wait: function () {
      while(!this.s.eof) {
        system.sleep(10);
      }
    }
  };
  
  var c1 = new Cmd("cmd.exe");
  c1.write("md " + BUILD);
  c1.write("del /f /s /q " + BUILD);
  c1.write("copy /y " + MAIN + " " + BUILD + "\\main.js");
  c1.write("exit");
  c1.wait();
  var c2 = new Cmd(ZIP + " " + BUILD + "\\" + OUT + ".zip " + SOURCE);
  c2.wait();
  system.setcwd(BUILD);
  var c3 = new Cmd(ZIP + " " + OUT + ".zip main.js"); 
  c3.wait();
  var c4 = new Cmd("cmd.exe");
  c4.write("copy /y /b " + JSDB + "+" + OUT + ".zip " + OUT + ".exe");
  c4.write("exit");
})();
